﻿using BLL;
using Models;
using Student;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Teacher
{
    public partial class Result_form : Form
    {
        List<Models.Stu_group> all_groups;
        List<Models.Stu_group> your_groups;
        public Result_form()
        {
            InitializeComponent();
        }

        private void Result_form_Load(object sender, EventArgs e)//窗口加载时运行的代码，其实是在查找数据并显示出来
        {
          //  // 隐藏“所有队伍”的标签和列表
          //  label3.Visible = false;
          //  group_list.Visible = false;

            B_Group b_Group = new B_Group();

            all_groups = b_Group.getList();
            //group_list.DataSource = all_groups;

            //group_list.Columns["major_id"].Visible = false;
            //group_list.Columns["times"].Visible = false;
            
            //group_list.Columns["group_id"].HeaderText = "学生组ID";
            //group_list.Columns["group_name"].HeaderText = "队伍名称";
            //group_list.Columns["grade"].HeaderText = "年级";
            //group_list.Columns["group_lead"].HeaderText = "组长ID";
            //group_list.Columns["project_name"].HeaderText = "项目名称";
            //group_list.Columns["project_info"].HeaderText = "简介";
            //group_list.Columns["teacher_id"].HeaderText = "教师ID";
            //group_list.Columns["teacher_name"].HeaderText = "教师姓名";
            //group_list.Columns["members"].HeaderText = "队伍人数";

            your_groups = all_groups.Where(g => g.teacher_id == log_info.teacher.teacher_id).ToList();
            your_Groups.DataSource = your_groups;

            your_Groups.Columns["major_id"].Visible = false;
            your_Groups.Columns["times"].Visible = false;
          
            your_Groups.Columns["group_id"].HeaderText = "学生组ID";
            your_Groups.Columns["group_name"].HeaderText = "队伍名称";
            your_Groups.Columns["grade"].HeaderText = "年级";
            your_Groups.Columns["group_lead"].HeaderText = "组长ID";
            your_Groups.Columns["project_name"].HeaderText = "项目名称";
            your_Groups.Columns["project_info"].HeaderText = "简介";
            your_Groups.Columns["teacher_id"].HeaderText = "教师ID";
            your_Groups.Columns["teacher_name"].HeaderText = "教师姓名";
            your_Groups.Columns["members"].HeaderText = "队伍人数";


        }

        private void your_Groups_MouseClick(object sender, MouseEventArgs e)
        {
            if (your_Groups.Rows.Count == 0)    return;
            
            if (your_Groups.CurrentCell == null) return;

            int idx = your_Groups.CurrentCell.RowIndex;
            BLL.B_Student b_Student = new BLL.B_Student();
            var stus = b_Student.GetList(your_groups[idx]);
            Group_members.DataSource = stus;

            Group_members.Columns["pwd"].Visible = false;
            Group_members.Columns["major_id"].Visible = false;

            Group_members.Columns["stu_id"].HeaderText = "学生ID";
            Group_members.Columns["stu_no"].HeaderText = "学号";
            Group_members.Columns["stu_name"].HeaderText = "姓名";
            Group_members.Columns["grade"].HeaderText = "年级";
            Group_members.Columns["phone"].HeaderText = "电话";
            Group_members.Columns["group_id"].HeaderText = "学生组ID";
            Group_members.Columns["is_gleader"].HeaderText = "是否为组长";

            Disp_Group_info(your_groups[idx]);
        }

        private void group_list_MouseClick(object sender, MouseEventArgs e)
        {
            //if (group_list.CurrentCell == null) return;

            //int idx = group_list.CurrentCell.RowIndex;

            BLL.B_Student b_Student = new BLL.B_Student();
            //var stus = b_Student.GetList(all_groups[idx]);

            //Group_members.DataSource = stus;

            Group_members.Columns["pwd"].Visible = false;
            Group_members.Columns["major_id"].Visible = false;
           
            Group_members.Columns["stu_id"].HeaderText = "学生ID";
            Group_members.Columns["stu_no"].HeaderText = "学号";
            Group_members.Columns["stu_name"].HeaderText = "姓名";
            Group_members.Columns["grade"].HeaderText = "年级";
            Group_members.Columns["phone"].HeaderText = "电话";
            Group_members.Columns["group_id"].HeaderText = "学生组ID";
            Group_members.Columns["is_gleader"].HeaderText = "是否为组长";

            //Disp_Group_info(all_groups[idx]);
        }

        private void Disp_Group_info(Models.Stu_group stu_Group)
        {
            Group_info.Text = stu_Group.project_info;
            Group_name.Text = stu_Group.group_name;
            Project_name.Text = stu_Group.project_name;
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
